<%--
  Created by IntelliJ IDEA.
  User: lanhai
  Date: 2021/4/4
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>测试AJAX</title>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body>
    <a href="test/ssm.html">测试SSM整合环境</a>
    <br/>
    <button id="btn1">发送[5,8,12]</button>
    <br/>
    <button id="btn2">发送Map数据</button>
    <br/>
    <br/>
    <button id="btn3">点击弹窗</button>
</body>

<script>
    $(function () {

        var array = {"array":[5,8,12]};
        var arrayJson = JSON.stringify(array);

        var map = {"name" : "张三", "age" : "18", "gender" : "man"};
        var mapJson = JSON.stringify(map);

        $("#btn1").click(function () {
            $.ajax({
                "url": "send/array.html",
                "type": "POST",
                "data": {
                    "array" : [5,8,12]
                },
                "dataType": "text",
                "traditional": "true",
                "success": function (res) {
                    alert(res);
                },
                "error": function (res) {
                    alert(res);
                }
            });
        });

        $("#btn2").click(function () {
            $.ajax({
                "url": "send/map.json",
                "type": "POST",
                "data": mapJson,
                "dataType": "json",
                "contentType": "application/json;charset=UTF-8",
                "traditional": "true",
                "success": function (res) {
                    console.log(res);
                },
                "error": function (res) {
                    console.log(res);
                }
            });
        });

        $("#btn3").click(function () {
            layer.msg("嘻嘻，我是layer的弹窗");
        });
    });
</script>

</html>
